﻿using LDM.Framework.Validation;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;


namespace Microsoft.Extensions.DependencyInjection;

public static class ExceptionHandlingServiceCollectionExtensions
{
    /// <summary>
    /// 添加异常处理服务扩展服务
    /// </summary>
    /// <param name="services"></param>
    /// <returns></returns>
    internal static IServiceCollection AddExceptionHandling(this IServiceCollection services)
    {
        // 是否抑制自带的模型验证
        services.Configure<ApiBehaviorOptions>(options => options.SuppressModelStateInvalidFilter = true);
        // 添加模型验证过滤器
        services.AddMvcFilter<ValidationFilter>();
       
        // 添加异常过滤器
        services.AddMvcFilter<ExceptionFilter>();

        return services;
    }
}
